import request from '@/request'


export function getArticles(query, page) {
  return request({
    url: '/article/forumArticle',
    method: 'post',
    data: {
      currentPage: page.pageNumber,
      pageSize: page.pageSize,
      name: page.name,
      year: query.year,
      month: query.month,
      tagId: query.tagId,
      categoryId: query.categoryId
    }
  })
}

/**
 * 最热文章获取
 * @returns 
 */
export function getHotArtices() {
  return request({
    url: '/article/forumArticle/hot',
    method: 'get'
  })
}

/**
 * 获取最新文章5篇
 * @returns 
 */
export function getNewArtices() {
  return request({
    url: '/article/forumArticle/new',
    method: 'get'
  })
}

export function viewArticle(id) {
  return request({
    url: `/articles/view/${id}`,
    method: 'post'
  })
}

export function getArticlesByCategory(id) {
  return request({
    url: `/articles/category/${id}`,
    method: 'post'
  })
}

export function getArticlesByTag(id) {
  return request({
    url: `/articles/tag/${id}`,
    method: 'post'
  })
}

/**
 * 发布文章
 * @param {文章对象} article 
 * @param {验证登录} token 
 * @returns 
 */
export function publishArticle(article,token) {
  return request({
    headers: {'Authorization': token},
    url: '/article/forumArticle/publish',
    method: 'post',
    data: article
  })
}


export function listArchives() {
  return request({
    url: '/articles/listArchives',
    method: 'post'
  })
}

/**
 * 通过id查询文章
 * @param {*} id 
 * @returns 
 */
export function getArticleById(id) {
  return request({
    url: `/articles/${id}`,
    method: 'post'
  })
}
